<template>
  <div class="login_container">
    <div class="login_box">
      <div class="avatar_box">
        <img  class="logoInf" src="../../assets/image/mengmanewlogo.png"  alt="请登录" />
      </div>
      <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" class="login_Form"  @keyup.enter.native="login">
        <el-form-item prop="userName">
          <el-input v-model="loginForm.userName" prefix-icon="el-icon-user" placeholder="会员号" ></el-input>
        </el-form-item>
          <el-form-item prop="userPassword">
          <el-input v-model="loginForm.userPassword" prefix-icon="el-icon-lock" placeholder="密码" type="password"></el-input>
        </el-form-item>
         <el-form-item class="btns">
          <el-button type="primary" @click="login">登录</el-button>
        <el-button type="primary" @click="resetLoginForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
data(){
    return{
        loginForm:{
                userName:'',
                userPassword:''

        },
        loginFormRules:{
          userName: [
            { required: true, message: '请输入会员号', trigger: 'blur' },
            { min: 3, max: 10, message: '长度在 3 到 6 个字符', trigger: 'blur' }
           
          ], 
          userPassword:[
              { required: true, message: '请输入密码', trigger: 'blur'},
              {min: 3, max: 10, message: '长度在 3 到 6 个字符', trigger: 'blur'}
              ]
        }
    }
},methods:{
 
    resetLoginForm(){
         this.$refs.loginFormRef.resetFields();
    },
    login(){
        //预验证
        this.$refs.loginFormRef.validate(async valid=>{
            
           if(!valid)return;
         const {data:res}= await this.$http.post('login',
           this.loginForm
          
         );
         if(res.code!==200)return this.$message.error(res.msg)
         this.$message.success(res.msg)


        window.sessionStorage.setItem("token",res.data);
         this.$router.push("/home")
        })
    },
     reload(){
        this.isRouterAlive = false;
        this.$nextTick(function () {
          this.isRouterAlive = true
          
        });
      }, 
},
created(){
 this.reload();
}

};
</script>
<style lang="less" scoped>
.login_container {
  background-color: #2b4b6b;
  height: 100%;
}
.login_box {
  width: 450px;
  height: 300px;
  background-color: aliceblue;
  border-radius: 15px;
  position: absolute;
  // left: 50%;
  top: 30%;
  left: -10%;
 //
  box-shadow: 0 0 10px #ddd;
  .avatar_box {
    height: 130px;
    width: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: aliceblue;
    }
  }
}
.btns{
display: flex;
justify-content:flex-end;
}
.login_Form{
position:absolute;
bottom: 0;
width: 100%;
padding: 0 70px;
box-sizing: border-box;
}
.logoInf{
height:  120%;

}
</style>